package com.tankgame.its381b;

import java.io.IOException;
import java.util.Random;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author open
 */
public class CloudSprite extends Sprite {

	//create new random variable r
    private static Random r;

    //set width and height to images values
    private static final int WIDTH = 16, HEIGHT = 16;

    //create sprite with cloud.png and set width and height
    public CloudSprite() throws IOException {
        super(Image.createImage("/res/cloud.png"), WIDTH, HEIGHT);
        defineReferencePixel(getWidth() / 2, getHeight());
        //new random int
        if( r == null ) {
            r = new Random();
        }
        //generate a random heigh value
        int randomh = (r.nextInt(60)+30);
        //set position of creation
        setPosition(0, randomh);
    }

    public void move() {
      //move sprite 2pixels along x axis
      move(2, 0);
    }

}